<link href="__PUBLIC__/css/page.css" rel="stylesheet"  type="text/css" />
<div class="pd-20">
	<form method="POST" action="{:U('Admin/Order/addPlusFood')}">
		<span>关键词：</span>
		<input type="text" class="input-text" id="keyword" name="keyword" style="width: 200px;" value="" placeholder="请输入关键字...">
		<input type="submit" class="btn btn-success" value="搜索"/>
	</form>
    <if condition="$schFoods eq null ">
        <div class="row">没有{:C('pom_admin_product_name')}</div>
        <else />
        <div class="mt-20">
        	
            <table class="table table-border table-bordered table-bg table-sort table-striped">
                <thead>
                    <tr class="text-c">
                        <th width="200">{:C('pom_admin_product_name')}名称</th>
                        <th width="auto">操作</th>
                    </tr>
                </thead>
                <tbody>
                    <volist name="schFoods" id="food">
                        <tr class="text-c" data-foodid="{$food['foodid']}">
                            <td>{$food.foodname}</td>
                            <td>
	                            <span class="attr" style="display:inline;">
	                            	库存<input type="text" name="" <if condition="$food['instock'] neq null">value="{$food['instock']}"<else/>value=""</if> class="instock" <if condition="$food['instock'] eq null"></if> style="width:60px;">
	                            </span>
                            	<a class="btn btn-success del_food" href="javascript:void(0);" <if condition="$plusFoods[$key] eq null">style="display:none;"<else/>style="display:inline;"</if>>删除</a>
                            	<a class="btn btn-success add_food" href="javascript:void(0);" <if condition="$plusFoods[$key] eq null">style="display:inline;"<else/>style="display:none;"</if>>加入</a>
                            </td>
                        </tr>
                    </volist>
                </tbody>
            </table>
        </div>
    </if>
    <div class="row cl dataTables_wrapper" id="upage">
        {$Page}
    </div>
</div>
<script type="text/javascript" src="__PUBLIC__/lib/layer/layer.js"></script>
<script>
//用户-编辑
function showFood(title, url, id, w, h) {
    layer_show(title, url, w, h);
}

function change(obj) {
	window.location.href="/index.php?g=Admin&m=Order&a=showAll&state="+$(obj).val();
}


$(document).ready(function(){
	// 处理分页链接，加入keyword，注意和thinkphp url模式适配
	$(".pager").find(".num").each(function(){
		var url = $(this).attr("href");
		if(url.indexOf("/keyword") == -1) {
			url = url + '/keyword/' + '{$keyword}';
			$(this).attr("href", url);
		}
	});
	
	// 从套餐中删除菜品
	$(".del_food").each(function(){
		$(this).click(function(){
			var that = $(this);
			var foodid = $(this).parents(".text-c").attr("data-foodid");
			$.ajax({
				url: "{:U('Admin/Order/del_food2plus')}",
				data: {
					foodid: foodid,
				},
				type: 'post',
				dataType: 'json',
				success: function(data) {
					that.css("display", "none");
					that.next().css("display", "inline");
					alert(data.result);
				},
				error: function() {
					alert("删除失败");
				}
			});
		});
	});
	
	// 往套餐中添加菜品
	$(".add_food").each(function(){
		$(this).click(function(){
			var that = $(this);
			var foodid = $(this).parents(".text-c").attr("data-foodid");
			var attrEl = $(this).parent();
			
			var instock = attrEl.find('.instock').val();
			// 对价格进行过滤 to do...
			
			var foodname = attrEl.prev().text();
			$.ajax({
				url: "{:U('Admin/Order/add_food2plus')}",
				data: {
					foodid: foodid,
					foodname: foodname,
					instock: instock,
				},
				type: 'post',
				dataType: 'json',
				success: function(data) {
					that.css("display", "none");
					that.prev().css("display", "inline");
					alert(data.result);
				},
				error: function() {
					alert("添加失败");
				}
			});
		});
	});
});

</script>
